package com.neusoft.neuiotms.sap;

import java.util.concurrent.Callable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.bizcore.notice.notification.dto.NoticeRecordDTO;
import com.neusoft.bizcore.notice.notification.service.NoticeService;
import com.neusoft.bizcore.notice.system.service.SystemNoticeService;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.utils.JsonUtils;
import com.neusoft.neuiotms.dcam.fixed.asynchronous.AsyncCallService;
import com.neusoft.neuiotms.micro.notice.NoticeMicroService;

@Service
public class NoticeMicroServiceImpl implements NoticeMicroService {

    @Autowired
    private NoticeService noticeService;
    @Autowired(required = false)
    private AsyncCallService callService;
    @Autowired
    private SystemNoticeService SystemNoticeService;

    @Override
    public ResultDTO<Void> createNotification(final String arg0) {
        final NoticeRecordDTO dto = JsonUtils.jsonToPojo(arg0, NoticeRecordDTO.class);
        final Callable<String> callable = () -> {
            NoticeMicroServiceImpl.this.noticeService.buildAndSendMessage(dto);
            return null;
        };
        this.callService.handle(callable);

        return ResultDTO.success();
    }

    @Override
    public ResultDTO<Void> notifyPage(final String path, final String message) {
        NoticeMicroServiceImpl.this.SystemNoticeService.notifyPage(path, message);
        return null;
    }

}
